package com.tan.androidtest.customview.canvas;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.tan.androidtest.R;

/**
 * 测试倒影
 */

public class TestDaoYingView extends View {

    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // 创建燕X轴的倒影图像
    private Matrix m = new Matrix();
    private Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_test1);

    private Bitmap t_bitmap;

    public TestDaoYingView(Context context) {
        this(context, null);
    }

    public TestDaoYingView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TestDaoYingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        m.setScale(1, -1);
        t_bitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), m, true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        //canvas.save();
        canvas.drawBitmap(mBitmap, 0, 0, mPaint);
        //canvas.restore();

        /*canvas.save();
        canvas.translate(0, 2 * mBitmap.getHeight());
        canvas.translate(mBitmap.getWidth(), 0);
        canvas.rotate(180);
        canvas.translate(0, -mBitmap.getHeight());
        canvas.drawBitmap(mBitmap, 0, mBitmap.getHeight(), mPaint);
        canvas.restore();*/
        canvas.drawBitmap(t_bitmap, 0, mBitmap.getHeight(), mPaint);
    }
}
